package com.bootdo.collection.utils;

import com.bootdo.collection.domain.PictureDO;

public class ReplacePicUrlToBase64Util implements Runnable{
    static Base64Utils base64Utils = new Base64Utils();
    String referValue;
    private PictureDO pictureDO;
    public ReplacePicUrlToBase64Util(PictureDO pictureDO,String referValue){
        this.pictureDO = pictureDO;
        this.referValue = referValue;
    }
    @Override
    public void run() {
        String base64String =  base64Utils.imageToBase64String(pictureDO,referValue);
        for(int i =0;i<3;i++){
            if(base64String == null){
                base64String = base64Utils.imageToBase64String(pictureDO,referValue);
            }
        }
        pictureDO.setPictureUrl("data:image/jpg;base64," + base64String);
    }

    public static void serialReplaceUrl(PictureDO pictureDO,String referValue){
        String base64String =  base64Utils.imageToBase64String(pictureDO,referValue);
        for(int i =0;i<3;i++){
            if(base64String == null){
                base64String = base64Utils.imageToBase64String(pictureDO,referValue);
            }
        }
        pictureDO.setPictureUrl("data:image/jpg;base64," + base64String);
    }
}
